package com.jdk.demo.unsafe;

public class OffHeapArrayDemo {
	
	public static void main(String[] args) {
		OffHeapArray offHeapArray = new OffHeapArray(4);
		offHeapArray.set(0, 1);
		offHeapArray.set(1, 2);
		offHeapArray.set(2, 3);
		offHeapArray.set(3, 4);
		offHeapArray.set(2, 5); // 在索引2的位置重复放入元素

		int sum = 0;
		for (int i = 0; i < offHeapArray.size(); i++) {
		    sum += offHeapArray.get(i);
		}
		// 打印12
		System.out.println(sum);

		offHeapArray.freeMemory();
	}

}
